﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EventDemo
{
    public class RecordListClass
    {
        List<RecordInfo> recordList = new List<RecordInfo>();

        public void ShowPage()
        {
            Console.WriteLine("********************************");
            Console.WriteLine("***********记录列表页***********");
            Console.WriteLine("-----------------------------------------------------");
            Console.WriteLine("1.添加新记录  2.退出 ");
            Console.WriteLine("-----------------------------------------------------");
            string choose = Console.ReadLine(); 
            while (true)
            {
                if (choose == "1")
                {
                    //打开添加记录信息页
                    AddRecord();
                }
                else if (choose == "2")
                {
                    Environment.Exit(0);
                }
            }
        }
        private void AddRecord()
        {
            RecordClass recordPage = new RecordClass();
            recordPage.Recorded += RecordPage_Recorded;//订阅事件（注册事件）
            recordPage.ShowPage();
        }


        //事件处理程序
        private void RecordPage_Recorded(object sender, RecordArgs e)
        {
            RecordInfo record = e.Record;//刷新的记录信息
            if (record != null)
            {
                recordList.Add(record);
                PrintRecords();
            }
        }

        private void PrintRecords()
        {
            foreach (RecordInfo record in recordList)
            {
                Console.WriteLine($"编号：{record.Id}; 描述：{record.Remark}");
            }
        }

    }
}
